package cn.cpf.springbootmybatisplus.modules.sys.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.cpf.springbootmybatisplus.modules.sys.entity.SysUsers;
import cn.cpf.springbootmybatisplus.modules.sys.service.SysUsersService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gf
 * @since 2019-01-04
 */
@RestController
@RequestMapping("/sysUsers")
public class SysUsersController {

    @Autowired
    SysUsersService sysUsersService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public List<SysUsers> getEmployees() {
        return sysUsersService.list( null );
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public SysUsers getEmployeeById(@PathVariable("id") int id) {
        return sysUsersService.getById( id );
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public String updateEmployee(@PathVariable("id") Long id, 
                                 @RequestParam(value = "gender", required = true) int gender ) {
    	SysUsers user = new SysUsers();
        user.setId( id );
        user.setName( "张" );
        user.setGender( 1 );
        boolean b = sysUsersService.updateById( user );
        if (b) {
            return "update success";
        } else {
            return "update fail";
        }

    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable(value = "id")int id) {
        boolean b = sysUsersService.removeById( id );
        if(b) {
            return "delete success";
        }else {
            return "delete fail";
        }

    }

    @RequestMapping("/add")
    public String postEmployee() {
    	SysUsers user = new SysUsers();
        user.setName( "王" );
        user.setGender( 2 );
        user.setAge(2);
        boolean b = sysUsersService.save( user );
        if(b) {
            return "sava success";
        }else {
            return "sava fail";
        }

    }
}

